<template>
  <div class="student-manage">
    <div class="head">全部用户</div>
    <div class="select-button">
      <el-row>
        <el-col :span="12">
          <el-row :gutter="20">
            <el-col :span="12">
              <el-input v-model="inputContext" placeholder="问题内容"></el-input>
            </el-col>
            <el-col :span="12">
              <el-input v-model="inputTitle" placeholder="问题标题" ></el-input>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="5" :offset="1">
          <el-select v-model="inputStatus" placeholder="审核状态">
            <el-option
                v-for="item in options"
                :key="item.value"
                :label="item.label"
                :value="item.value">
            </el-option>
          </el-select>
        </el-col>
        <el-col :span="3">
          <el-button  type="primary" icon="el-icon-search" @click="pageQuestions()">查询</el-button>
        </el-col>
        <el-col :span="3">
          <el-button  type="primary" icon="el-icon-search" @click="clear()">清空</el-button>
        </el-col>


      </el-row>
    </div>
    <div class="student-list" style="display: flex;flex-direction: column;align-items: center">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column type="selection" width="55"  align="center">
        </el-table-column>
        <el-table-column fixed prop="id" label="问题ID" min-width="50%" align="center">
        </el-table-column>
        <el-table-column prop="nickName" label="用户昵称" min-width="40%" align="center" >
        </el-table-column>
        <el-table-column prop="title" label="问题标题" min-width="40%" align="center" >
        </el-table-column>
        <el-table-column label="hula币/积分" min-width="40%" align="center" >
          <template slot-scope="scope">
            <div>{{scope.row.hulaCoin}}/{{scope.row.hulaScore}}</div>
          </template>
        </el-table-column>
        <el-table-column label="热点问题/专业提问" min-width="40%" align="center" >
          <template slot-scope="scope">
            <div>{{scope.row.isHot==true?"是":"否"}}/{{scope.row.isSpecial==true?"是":"否"}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="审核状态" min-width="40%" align="center" >
          <template slot-scope="scope">
            <div>{{statusTypes[scope.row.status]}}</div>
          </template>
        </el-table-column>

        <el-table-column prop="context" label="内容" min-width="40%" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{scope.row.context.replace(/<[^>]+>/g,"")}}
          </template>
        </el-table-column>
        <el-table-column prop="gmtCreate" label="发布时间" min-width="50%" align="center" >
        </el-table-column>
        <el-table-column label="操作" align="center" fixed="right" width="100px">
          <template slot-scope="scope">
            <el-button type="text" size="medium" @click="updateQuestion(scope.row.id)">编辑问题</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="block" style="margin-top: 20px">
        <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[8, 10, 20, 40]"
            :page-size="8"
            layout="total, sizes, prev, pager, next, jumper"
            :total="parseInt(total)">
        </el-pagination>
      </div>
    </div>


  </div>
</template>

<script>
import WangEditor from "@/components/WangEditor.vue";
export default {
  name: "StudentManageView",
  components : {WangEditor},
  data() {
    return {
      total: 0,
      currentSize: 8,
      currentPage: 1,
      inputNickName:"",
      inputTitle:"",
      inputContext:"",
      inputStatus:"",

      statusTypes:['待审核','审核通过','审核不通过'],
      options: [{
        value: 0,
        label: '待审核'
      }, {
        value: 1,
        label: '审核通过'
      },{
        value: 2,
        label: '审核不通过'
      }]

    };
  },
  mounted() {
    this.pageQuestions();
  },
  methods: {
    pageQuestions() {
      this.$api.pageQuestions({
        pageSize: this.currentSize,
        pageNow: this.currentPage,
        nickName: this.inputNickName || '',
        context : this.inputContext,
        title:this.inputTitle,
        status:this.inputStatus
      })
          .then((res) => {
            let list = res.data.rows;
            this.total = res.data.totalPage
            console.log(this.total)
            this.tableData = list
          });
    },
    updateQuestion(questionId){
      this.$router.push({path:`/home/create/question-info-edit/${questionId}`})
    },
    clear(){
      this.inputNickName = ''
      this.inputContext = ''
      this.inputTitle = ''
      this.inputStatus = ''
      this.pageQuestions();
    }

  },
};
</script>

<style scoped>
.student-manage{
  margin-top: 20px;
  width: 100%;
}


.head {
  padding-bottom: 10px;
}

.select-button {
  padding: 10px 0;
}

.student-list {
  width: 100%;
  padding: 10px 0;
  display: flex;
}
</style>
